﻿using System;
using ProtoBuf;

namespace JmShared
{
    [ProtoContract]
    public struct DeviceInfo
    {
        [ProtoMember(1)]
        public bool? IsTileEnabled { get; set; }

        [ProtoMember(2)]
        public bool? IsToastEnabled { get; set; }

        [ProtoMember(3)]
        public bool? IsActive { get; set; }

        [ProtoMember(4)]
        public bool? StoreMessagesWhileOffline { get; set; }

        [ProtoMember(5)]
        public int? OfflineMessagesCountLimit { get; set; }

        [ProtoMember(6)]
        public int? OfflineMessagesAgeLimit { get; set; }
        [ProtoMember(7)]
        public bool? SendPmPushWhileOffline { get; set; }
        [ProtoMember(8)]
        public bool? SendGroupPushWhileOffline { get; set; }
        //[ProtoMember(4)]
        //public bool StoreMessagesWhileOffline { get; set; }
    }

    [ProtoContract]
    public struct LoginInfo
    {
        [ProtoMember(1)]
        public string Username { get; set; }
        [ProtoMember(2)]
        public string Password { get; set; }
        [ProtoMember(3)]
        public string NickName { get; set; }
        [ProtoMember(4)]
        public string Color { get; set; }
        [ProtoMember(5)]
        public string FontName { get; set; }
        [ProtoMember(6)]
        public string FontStyle { get; set; }
    }

    [ProtoContract]
    public class ChatMessage
    {
        #region Fields

        private string _message;

        #endregion

        #region Constructor

        #endregion

        #region Properties

        [ProtoMember(1, IsRequired = true)]
        public MessageType MessageType { get; set; }

        [ProtoMember(2)]
        public UserInfo[] UserInfo { get; set; }

        [ProtoMember(3)]
        public UserInfo Sender { get; set; }

        [ProtoMember(4)]
        public string Message
        {
            get { return this._message ?? String.Empty; }
            set { this._message = value; }
        }
        [ProtoMember(5)]
        public DateTime TimeStampMessageRelayed { get; set; }

        [ProtoMember(6)]
        public int? MessageID { get; set; }

        public override string ToString()
        {
            return Message;
        }
        #endregion
    }
    [ProtoContract]
    public class UserInfo : IEquatable<UserInfo>
    {
        #region Properties
        public string UserID
        {
            get { return UserName + "#" + ID; }
        }
        /// <summary>
        /// Returns the users nickname if available, returns the username if not.
        /// </summary>
        public string PrettyName
        {
            get { return String.IsNullOrEmpty(this.NickName) ? this.UserName : this.NickName; }
        }

        [ProtoMember(1)]
        public string NickName { get; set; }

        [ProtoMember(2)]
        public string UserName { get; set; }

        [ProtoMember(3)]
        public string FontName { get; set; }

        [ProtoMember(4)]
        public string FontStyle { get; set; }

        [ProtoMember(5)]
        public string Color { get; set; }

        [ProtoMember(6)]
        public string ID { private get; set; }

        [ProtoMember(7)]
        public ClientStatus ClientStatus { get; set; }

        [ProtoMember(8)]
        public DateTime? TimestampAfk { get; set; }

        [ProtoMember(9)]
        public string ClientVersion { get; set; }

        #endregion

        #region Methods

        public override string ToString()
        {
            return UserName;
        }



        public bool Equals(UserInfo u)
        {
            return this.UserName == u.UserName && this.ID == u.ID;
        }
        #endregion
    }

    [ProtoContract]
    public enum ClientStatus
    {
        Available = 0,
        Afk,
        Busy
    }
    [ProtoContract]
    public enum MessageType
    {
        Error = 0,
        Login,
        Authenticated,
        Hello,
        Logout,
        Message,
        IsWriting,
        BroadcastEmoticons,
        RequestingEmoticon,
        SendingEmoticon,
        LoginFailed,
        LoginSuccessful,
        AFK,
        Busy,
        Nudge,
        PM,
        PushUri,
        UpdateUserInfo,
        ResetUnreadMessageCount,
        UpdateDeviceStatus
    }
}
